﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace MvdDonk.Bomberman.HUD
{
    class DebugBox
    {
        private SpriteFont font;
        private Dictionary<string, string> lines;
        private int last;

        public DebugBox()
        {
            lines = new Dictionary<string, string>();
        }

        public void Initialize()
        {
            font = Bomberman.Instance.ResourceManager.RequestFont("DebugBox");
        }

        public void Update(GameTime gameTime)
        {
            int now = System.DateTime.Now.Millisecond;
            int fps;
            if (now == last)
                fps = 60;
            else
                fps = (int)((1.0f / (float)(now - this.last)) * 1000.0f);
            this.last = System.DateTime.Now.Millisecond;

            this.AddOutput("HUD", "0");
            this.AddOutput("FPS", fps.ToString());
        }

        public void AddOutput(string label, string value)
        {
            if (!lines.ContainsKey(label))
                lines.Add(label, value);
            else
                lines[label] = value;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            var output = new StringBuilder();
            foreach (var line in lines)
            {
                output.Append(line.Key);
                output.Append(": ");
                output.AppendLine(line.Value);
            }

            spriteBatch.DrawString(font, output.ToString(), new Vector2(0, 0), Color.White);
        }
    }
}
